package com.xzy.Config;

import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Component
public class SystInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("被拦截了");
        HttpSession session=request.getSession();
        Object nowUser = session.getAttribute("nowUser");
        Object name= request.getParameter("name");
        if(nowUser!=null||name!=null){
            return true;
        }else {
            request.getRequestDispatcher("/").forward(request,response);
            return false;
        }

    }
}
